%{
	#include <stdlib.h>
	#include "global.h"
	#include "TablicaSymboli.h"
	int lineno = 1;
	int tokenval = NONE;
	using namespace std;

%}

WHITE		[[:blank:]]
NEW_LINE	"\n"
SIMPLEDIGIT	[[:digit:]]+
FRACDIGIT	{SIMPLEDIGIT}("."{SIMPLEDIGIT})?
FULLDIGIT	{FRACDIGIT}([Ee]{SIGNS}?{FRACDIGIT})?
ALPHA		[[:alpha:]]
ALNUM		[[:alnum:]]
DIV			"/"|"div"
MUL			"*"|"mul"
SIGNS		"+"|"-"
COMMENTS	\{[^\{]*\}

%option noyywrap
%option nounput

%%

{WHITE}			{}

{NEW_LINE}		{
				lineno++;
				cout<<endl;
				}

{FULLDIGIT}		{
            	cout<<"["<<lineno<<"]"<<"FULLDIGIT"<<endl;
            	TablicaSymboli* tablica = TablicaSymboli::getInstance();
            	yylval.symbol = tablica->insert(yytext,NUM);
				return NUM;
				}

"not"			{
	            cout<<"["<<lineno<<"]"<<"not"<<endl;
	            yylval.val=NOT;
				return NOT;
				}

"+"				{
            	cout<<"["<<lineno<<"]"<<"PLUS"<<endl;
            	yylval.val=PLUS;
				return SIGN;
				}
				
"-"				{
            	cout<<"["<<lineno<<"]"<<"MINUS"<<endl;
            	yylval.val=MINUS;
				return SIGN;
				}				
				
"or"			{
				cout<<"["<<lineno<<"]"<<"or"<<endl;
				yylval.val=OR;
				return OR;
				}

":="			{
				cout<<"["<<lineno<<"]"<<"ASSIGNOP"<<endl;
				yylval.val=ASSIGNOP;
				return ASSIGNOP;
				}

"if"			{
				cout<<"["<<lineno<<"]"<<"if"<<endl;
				yylval.val=IF;
				return IF;
				}

"then"			{
				cout<<"["<<lineno<<"]"<<"then"<<endl;
				yylval.val=THEN;
				return THEN;
				}

"else"			{
				cout<<"["<<lineno<<"]"<<"else"<<endl;
				yylval.val=ELSE;
				return ELSE;
				}

"while"			{
				cout<<"["<<lineno<<"]"<<"while"<<endl;
				yylval.val=WHILE;
				return WHILE;
				}

"do"			{
				cout<<"["<<lineno<<"]"<<"do"<<endl;
				yylval.val=DO;
				return DO;
				}

"begin"			{
				cout<<"["<<lineno<<"]"<<"begin"<<endl;
				yylval.val=TBEGIN;
				return TBEGIN;
				}

"end"			{
				cout<<"["<<lineno<<"]"<<"end"<<endl;
				TablicaSymboli* tablica = TablicaSymboli::getInstance();
				tablica->log();
				yylval.val=END;
				return END;
				}

"function"		{
				cout<<"["<<lineno<<"]"<<"function"<<endl;
				yylval.val=FUNCTION;
				return FUNCTION;
				}

"procedure"		{
				cout<<"["<<lineno<<"]"<<"procedure"<<endl;
				yylval.val=PROCEDURE;
				return PROCEDURE;
				}

"var"			{
				cout<<"["<<lineno<<"]"<<"var"<<endl;
				yylval.val=VAR;
				return VAR;
				}

"integer"		{
				cout<<"["<<lineno<<"]"<<"integer"<<endl;
				yylval.val=INTEGER;
				return INTEGER;
				}

"real"			{
				cout<<"["<<lineno<<"]"<<"real"<<endl;
				yylval.val=REAL;
				return REAL;
				}

"array"			{
				cout<<"["<<lineno<<"]"<<"array"<<endl;
				yylval.val=ARRAY;
				return ARRAY;
				}

"of"			{
				cout<<"["<<lineno<<"]"<<"of"<<endl;
				yylval.val=OF;
				return OF;
				}

"program"		{
				cout<<"["<<lineno<<"]"<<"program"<<endl;
            	yylval.val = PROGRAM;
				return PROGRAM;
				}

{DIV}			{
				cout<<"["<<lineno<<"]"<<"div"<<endl;
				yylval.val = DIV;
				return MULOP;
				}
				
{MUL}			{
				cout<<"["<<lineno<<"]"<<"mul"<<endl;
				yylval.val = MUL;
				return MULOP;
				}
				
"and"			{
				cout<<"["<<lineno<<"]"<<"and"<<endl;
				yylval.val = AND;
				return MULOP;
				}
				
"mod"			{
				cout<<"["<<lineno<<"]"<<"mod"<<endl;
				yylval.val = MOD;
				return MULOP;
				}
				
"="				{
				cout<<"["<<lineno<<"]"<<"="<<endl;
				yylval.val = EQ;
				return RELOP;
				}
				
"<>"			{
				cout<<"["<<lineno<<"]"<<"<>"<<endl;
				yylval.val = NE;
				return RELOP;
				}
				
"<"				{
				cout<<"["<<lineno<<"]"<<"<"<<endl;
				yylval.val = LT;
				return RELOP;
				}
				
">"				{
				cout<<"["<<lineno<<"]"<<">"<<endl;
				yylval.val = GT;
				return RELOP;
				}
				
"<="			{
				cout<<"["<<lineno<<"]"<<"<="<<endl;
				yylval.val = LE;
				return RELOP;
				}
				
">="				{
				cout<<"["<<lineno<<"]"<<">="<<endl;
				yylval.val = GE;
				return RELOP;
				}
				
".."			{
				cout<<"["<<lineno<<"]"<<".."<<endl;
				yylval.val=DOTDOT;
				return DOTDOT;
				}

{ALPHA}{ALNUM}* {
				cout<<"["<<lineno<<"]"<<"ID"<<endl;
				TablicaSymboli* tablica = TablicaSymboli::getInstance();
            	yylval.symbol = tablica->insert(yytext,ID);
				return ID;
				}

<<EOF>>			{
				cout<<"["<<lineno<<"]"<<"EOF"<<endl;
				cout<<"Tablica symboli"<<endl;
				TablicaSymboli* tablica = TablicaSymboli::getInstance();
				tablica->log();
				return 0;
				}
{COMMENTS}		{}
.				{
				yylval.val = NONE;
				cout << "wypisuje yytext[0]"<<endl;
				return yytext[0];
				}
